package example.service;

import example.mapper.StorageRecordMapper;
import example.pojo.StorageRecord;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service("recordService")
public class StorageRecordServiceImpl implements StorageRecordService {
    @Resource
    private StorageRecordMapper recordMapper;

    @Override
    public int add(StorageRecord record) {
        int count = 0;
        try {
            count = recordMapper.add(record);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        return count;
    }

    @Override
    public int upd(StorageRecord record) {
        int count = 0;
        try {
            count = recordMapper.upd(record);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        return count;
    }

    @Override
    public int del(Integer id) {
        int count = 0;
        try {
            count = recordMapper.del(id);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        return count;
    }

    @Override
    public StorageRecord view(Integer id) {
        StorageRecord record = null;
        try {
            record = recordMapper.view(id);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        return record;
    }

    @Override
    public List<StorageRecord> select(String goodsName, Integer supplierId, Integer payStatus, Integer pageBegin, Integer pageSize) {
        List<StorageRecord> recordList = new ArrayList<>();
        try {
            recordList = recordMapper.select(goodsName, supplierId, payStatus, ((pageBegin - 1) * pageSize), pageSize);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        return recordList;
    }

    @Override
    public int count(String goodsName, Integer supplierId, Integer payStatus) {
        int count = 0;
        try {
            count = recordMapper.count(goodsName, supplierId, payStatus);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        return count;
    }

    @Override
    public int getRByS(Integer supId) {
        int count = 0;
        try {
            count = recordMapper.getRByS(supId);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        return count;
    }
}
